package io.jft.doll.ui.launch

import android.databinding.ObservableField
import android.os.Bundle
import android.os.CountDownTimer
import android.view.View
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.bumptech.glide.Glide
import com.g.base.router.BasePage
import com.g.base.token.TokenManage
import com.g.base.ui.BaseActivity
import io.jft.doll.R
import io.jft.doll.databinding.ActivityLaunchBinding
import io.jft.doll.router.RouterPage

@Route(path = RouterPage.LaunchActivity)
class LaunchActivity : BaseActivity<ActivityLaunchBinding>() {
    override var isFullScreen: Boolean = true

    val time = ObservableField("")

    private val countDownTimer: CountDownTimer = object : CountDownTimer(4000L, 1000L) {
        override fun onFinish() {
            finishAfterTransition()
        }

        override fun onTick(p0: Long) {
            time.set((p0 / 1000L).toString())
        }
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_launch)
        Glide.with(this).load(R.drawable.img_launch).crossFade().into(contentView.backgroundImage)
        contentView.data = this
        countDownTimer.start()
        showContentView()
    }

    fun onSkipClick(view: View) {
        countDownTimer.cancel()
        finishAfterTransition()
    }

    override fun onBackPressed() {}

    override fun supportSlideBack(): Boolean = false

    override fun finishAfterTransition() {
        super.finishAfterTransition()
        if (!TokenManage.isOauth()) {
            ARouter.getInstance().build(BasePage.Oauth).navigation(this)
        }
    }
}